package com.iemes.controller.mould;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.PrepareFormMap;
import com.iemes.mapper.mould.PrepareMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.MyDateUtils;

@RequestMapping("/pTransport/")
@Controller
public class PTransportController extends BaseController {

	@Inject
	private PrepareMapper prepareMapper;
	
	@RequestMapping("examineOrder")
	public String examineOrder(Model model){
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/mould/pTransport/pTransport_list";
	}
	
	@ResponseBody
	@RequestMapping("pTransport_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		PrepareFormMap prepareFormMap = getFormMap(PrepareFormMap.class);
		List<Map<String, Object>> prepare = prepareMapper.getAll(prepareFormMap);
		LuogicPaging(pageNow, pageSize, prepare);
		return pageView;
	}
	
	@RequestMapping("pTransport_edit")
	public String editUI(Model model) throws Exception 
	{
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			Map<String, Object> pTransport = prepareMapper.getById(id);
			model.addAttribute("pTransport",pTransport);
		}
		return Common.BACKGROUND_PATH + "/mould/pTransport/pTransport_edit";
	}
	
	@ResponseBody
	@RequestMapping(value="pTransport_editEntity")
	@SystemLog(module="备模指令",methods="备模指令表-修改备模运输表")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		PrepareFormMap prepareFormMap = getFormMap(PrepareFormMap.class);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		Session session = SecurityUtils.getSubject().getSession();
		prepareFormMap.put("beginTime", sdf.format(date));
		prepareFormMap.put("beginTimePeopleId", session.getAttribute("userSessionId"));
		prepareMapper.editEntity(prepareFormMap);
		return "success";
	}
}
